class StockSpanner
{
public:
    StockSpanner()
    {
        nextId = 0;
    }

    int next(int price)
    {
        while (!s.empty())
        {
            if (s.top().first <= price)
            {
                s.pop();
            }
            else
            {
                break;
            }
        }
        int span = nextId;
        if (!s.empty())
        {
            span -= s.top().second;
        }
        else
        {
            span += 1;
        }
        s.push({price, nextId});
        ++nextId;
        return span;
    }

    int nextId;
    stack<pair<int, int>> s;
};

/**
 * Your StockSpanner object will be instantiated and called as such:
 * StockSpanner* obj = new StockSpanner();
 * int param_1 = obj->next(price);
 */